package utils;

import java.util.Random;

public class RandomGenerator {
	private static RandomGenerator INSTANCE;
	private Random r;
	
	private RandomGenerator(long seed) {
		r = seed == -1 ? new Random() : new Random(seed);
	}
	
	public static void initialize(long seed) {
		INSTANCE = new RandomGenerator(seed);
	}
	
	private static synchronized RandomGenerator getInstance() {
		if (INSTANCE == null) {
			throw new IllegalStateException("Initialize random generator first.");
		} 
		return INSTANCE;
	}
	
	private Random getGenerator() {
		return r;
	}
	
	public static int getRandomInt(int max) {
		return getInstance().getGenerator().nextInt(max);
	}
	
	public static float getRandomFloat() {
		return getInstance().getGenerator().nextFloat();
	}

}
